home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 386 / algrtest / clr_mem.s < prev    next >
Text File  |  1985-11-19  |  7KB  |  164 lines

  1.  ; Program Name: CLR_MEM.S
  2.  ;      Version: 1.005
  3.  
  4.  ; Assembly Instructions:
  5.  
  6.  ;     Assemble in PC-relative mode save with a TOS extension.
  7.  
  8.  ; Execution Instructions:
  9.  
  10.  ;     Execute from the desktop; or execute SPAWN.TTP, type CLR_MEM.TOS on
  11.  ; its command line and view this program's output in CLR_MEM.DAT.
  12.  
  13.  ; Program Function:
  14.  
  15.  ;     Expands the concepts established with program PUSHZERO.  Here,
  16.  ; simulating the type of algorithm that would be used to clear video screen
  17.  ; memory, the execution time when clearing memory a longword each time,
  18.  ; within a loop, is compared to that of the more obvious method of clearing
  19.  ; a byte, or perhaps a word, each time through the loop.
  20.  
  21.  ;     Then, the speed advantage of clearing a longword by storing the
  22.  ; content of a cleared register is illustrated.
  23.  
  24.  ;     Finally, the advantage of clearing more than one longword within the
  25.  ; body of the loop is explored, with an eye out for the maximum amount of
  26.  ; beneficial loop expansion.
  27.  
  28. calculate_program_size:
  29.  lea        -$102(pc), a1       ; Fetch basepage start address.
  30.  lea        array, a0           ; Fetch program end = array address.
  31.  adda.l     #32000, a0          ; Add in array space.
  32.  movea.l    a0, a7              ; Point A7 to this program's stack.
  33.  trap       #6                  ; Return unused memory to op system.
  34.  
  35. print_heading:
  36.  lea        heading, a0
  37.  bsr        print_string
  38.  
  39. clear_one_byte_algorithm:
  40.  lea        header_1, a0
  41.  bsr        print_string
  42.  lea        array, a0           ; A0 is pointer to 32000 byte array.
  43.  move.l     #31999, d7          ; D7 is counter for the clear loop.
  44.  trap       #3                  ; Fetch start time.
  45.  move.l     d0, d3              ; Save start_time in D3.
  46. clear_a_byte:
  47.  move.b     #0, (a0)+          
  48.  dbra       d7, clear_a_byte    ; Loop 32000 times.
  49.  trap       #3                  ; Fetch end time.
  50.  sub.l      d3, d0              ; Subtract start time from end time.
  51.  trap       #10                 ; Convert to decimal milliseconds and print.
  52.  
  53. clear_one_word_algorithm:
  54.  lea        header_2, a0
  55.  bsr        print_string
  56.  lea        array, a0           ; A0 is pointer to 32000 byte array.
  57.  move.l     #15999, d7          ; D7 is counter for the clear loop.
  58.  trap       #3                  ; Fetch start time.
  59.  move.l     d0, d3              ; Save start_time in D3.
  60. clear_a_word:
  61.  move.w     #0, (a0)+          
  62.  dbra       d7, clear_a_word    ; Loop 16000 times.
  63.  trap       #3                  ; Fetch end time.
  64.  sub.l      d3, d0              ; Subtract start time from end time.
  65.  trap       #10                 ; Convert to decimal milliseconds and print.
  66.  
  67. clear_one_longword_algorithm:
  68.  lea        header_3, a0
  69.  bsr        print_string
  70.  lea        array, a0
  71.  move.l     #7999, d7
  72.  trap       #3                  ; Fetch start time.
  73.  move.l     d0, d3              ; Save start_time in D3.          
  74. clear_a_longword:
  75.  move.l     #0, (a0)+          
  76.  dbra       d7, clear_a_longword; Loop 8000 times.
  77.  trap       #3                  ; Fetch end time.
  78.  sub.l      d3, d0              ; Subtract start time from end time.
  79.  trap       #10                 ; Convert to decimal milliseconds and print.
  80.  
  81. clear_one_longword_with_precleared_register:
  82.  lea        header_4, a0
  83.  bsr        print_string
  84.  lea        array, a0
  85.  moveq      #0, d1              ; Preclear D1 for use in the loop.
  86.  move.l     #7999, d7
  87.  trap       #3                  ; Fetch start time.
  88.  move.l     d0, d3              ; Save start_time in D3.          
  89. clear_with_register:
  90.  move.l     d1, (a0)+           ; Clear a longword.
  91.  dbra       d7, clear_with_register
  92.  trap       #3                  ; Fetch end time.
  93.  sub.l      d3, d0              ; Subtract start time from end time.
  94.  trap       #10                 ; Convert to decimal milliseconds and print.
  95.  
  96. clear_4_longwords_algorithm:
  97.  lea        header_5, a0
  98.  bsr.s      print_string
  99.  lea        array, a0
  100.  move.l     #0, d1              ; Preclear D1 for use in the loop.
  101.  move.l     #1999, d7
  102.  trap       #3                  ; Fetch start time.
  103.  move.l     d0, d3              ; Save start_time in D3.         
  104. clr_4_longwords:          
  105.  move.l     d1, (a0)+           ; A single move statement clears 4 bytes.
  106.  move.l     d1, (a0)+           ; Reduces number of loops to 4000.
  107.  move.l     d1, (a0)+           ; Reduces number of loops to 2666+.
  108.  move.l     d1, (a0)+           ; Reduces number of loops to 2000.
  109.  dbra       d7, clr_4_longwords ; Loop 2000 times, clear 16 bytes each time.
  110.  trap       #3                  ; Fetch end time.
  111.  sub.l      d3, d0              ; Subtract start time from end time.
  112.  trap       #10                 ; Convert to decimal milliseconds and print.
  113.  
  114. clear_8_longwords_algorithm:    ; Will a further increase in move instructions
  115.  lea        header_6, a0        ; within the loop decrease execution time?
  116.  bsr.s      print_string
  117.  lea        array, a0  
  118.  move.l     #0, d1              ; Preclear D1 for use in the loop.
  119.  move.l     #999, d7
  120.  trap       #3                  ; Fetch start time.
  121.  move.l     d0, d3              ; Save start_time in D3.
  122. clr_8_longwords:
  123.  move.l     d1, (a0)+           ; A single move statement clears 4 bytes.
  124.  move.l     d1, (a0)+           ; Reduces number of loops to 4000.
  125.  move.l     d1, (a0)+           ; Reduces number of loops to 2666+.
  126.  move.l     d1, (a0)+           ; Reduces number of loops to 2000.
  127.  move.l     d1, (a0)+           ; Reduces number of loops to 1600.
  128.  move.l     d1, (a0)+           ; Reduces number of loops to 1333+.
  129.  move.l     d1, (a0)+           ; Reduces number of loops to 1142+.
  130.  move.l     d1, (a0)+           ; Reduces number of loops to 1000.
  131.  dbra       d7, clr_8_longwords ; Loop 1000 times, clear 32 bytes each time.
  132.  trap       #3                  ; Fetch end time.
  133.  sub.l      d3, d0              ; Subtract start time from end time.
  134.  trap       #10                 ; Convert to decimal milliseconds and print.
  135.  
  136. terminate:
  137.  trap       #8
  138.  
  139.  ;
  140.  ; SUBROUTINES
  141.  ;
  142.  
  143. print_string:                   ; Expects address of string to be in A0.
  144.  move.l     a0, -(sp)           ; Push address of string onto stack.
  145.  move.w     #9, -(sp)           ; Function = c_conws = GEMDOS $9.
  146.  trap       #1                  ; GEMDOS call
  147.  addq.l     #6, sp              ; Reset stack pointer to top of stack.
  148.  rts
  149.  
  150.  data
  151. heading:        dc.b 'CLR_MEM Execution Results',$D,$A,0
  152. header_1:       dc.b '   Clear one byte time:     ',0
  153. header_2:       dc.b '   Clear one word time:     ',0
  154. header_3:       dc.b '   Clear one longword time: ',0
  155. header_4:       dc.b '   With register time:      ',0
  156. header_5:       dc.b '   Clear 4 longwords time:  ',0
  157. header_6:       dc.b '   Clear 8 longwords time:  ',0
  158.  bss
  159.  align            
  160.                  ds.l    96    ; Stack.
  161. stack:           ds.l     1    ; Address of stack.
  162. array:           ds.l     0
  163.  end
  164.